package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * 类描述：
 */
@Api(tags = "商家端订单管理接口")
@RestController
@RequestMapping("/admin/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation("订单搜索")
    @GetMapping("/conditionSearch")
    public Result conditionSearch(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate beginTime,
                                   @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate endTime,
                                   Integer number, @RequestParam Integer page,@RequestParam Integer pageSize,
                                   String phone,Integer status) {
        PageResult pageResult=orderService.conditionSearch(beginTime,endTime,number,page,pageSize,phone,status);
        return Result.success(pageResult);
    }

    @ApiOperation("查看订单详情")
    @GetMapping("/details/{id}")
    public Result getOrderById(@PathVariable Long id) {
        //直接调直接用户端查看订单详情的借口而即可
        OrderVO orderVO =orderService.getOrderDetailByOrderId(id);
        return Result.success(orderVO);
    }

    @ApiOperation("订单数量统计")
    @GetMapping("/statistics")
    public Result getNumberByStatus() {
        OrderStatisticsVO orderStatisticsVO =orderService.getNumberByStatus();
        return Result.success(orderStatisticsVO);
    }

    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result confirmOrder(@RequestBody OrdersConfirmDTO dto) {
        orderService.confirmOrder(dto);
        return Result.success();
    }

    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result rejectionOrder(@RequestBody OrdersRejectionDTO dto) {
        orderService.rejectionOrder(dto);
        return Result.success();
    }
    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result cancelOrder(@RequestBody OrdersCancelDTO dto) {
        orderService.adminCancelOrder(dto);
        return Result.success();
    }
    @ApiOperation("派送订单")
    @PutMapping("/delivery/{id}")
    public Result deliveryOrder(@PathVariable Long id) {
        orderService.deliveryOrder(id);
        return Result.success();
    }
    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result completeOrder(@PathVariable Long id) {
        orderService.completeOrder(id);
        return Result.success();
    }
}
